#include <cstdio>

int n, i = 0;
long long r = 0, c = 0, o = 0;
char str[100005];

int main() {
    scanf("%d%s", &n, str);
    for (; i < n; i++)
        if (str[i] == 'C')
            c++;
        else if (str[i] == 'O')
            o += c;
        else
            r += o;
    printf("%lld", r);
    return 0;
}